package com.bjsxt.service.impl;

import com.bjsxt.mapper.HostMapper;
import com.bjsxt.mapper.HostPowerMapper;
import com.bjsxt.pojo.Host;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.HostService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class HostServiceImpl  implements HostService {

    @Autowired
    private HostMapper  hostMapper;

    @Autowired
    private HostPowerMapper  hostPowerMapper;


    @Override
    public PageA<Host> findMore(Integer page, Integer rows,Host host) {

        Page  pg = PageHelper.startPage(page, rows);

        List<Host> list = hostMapper.selectMore(host);

        PageA<Host>  pga=new PageA<>(list,pg.getTotal());

        return pga;
    }

    @Override
    public Integer changeStrong(Integer strong, Integer hid) {
        return hostMapper.updateStrong(strong, hid);
    }

    @Override
    public Integer save(Host host) {

        //添加主持人信息
        Integer insert = hostMapper.insert(host);
        //添加主持人权限的实现
        Integer insert1 = hostPowerMapper.insert(host.getHid());

        if(insert>0&&insert1>0){
            return 1;
        }
        return 0;
    }

    @Override
    public Integer changeStatus(Integer[] hids, String status) {

        int  a =0;
        try {
            for (Integer hid:hids){
                hostMapper.updateStatus(hid,status);
            }
            a=1;
        } catch (Exception e) {
            throw   e;

        }

        return a;
    }
}
